﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TimerManager : MonoBehaviour
{
    private List<Timer> timers = new List<Timer>();
    private float nowTime = 0;

    public static TimerManager Instance;

    private void Awake()
    {
        Instance = this;
    }

    public void AddTimer(Timer timer)
    {
        timers.Add(timer);
    }

    public void Update()
    {
        for (int i = timers.Count-1; i >=0 ; i--)
        {
            if (timers[i].isRun&&timers[i].AddTime(Time.deltaTime)&&!timers[i].IsLoop)
            {
                RemoveTimer(timers[i]);
            }
        }
    }

    public void RemoveTimer(Timer timer)
    {
        timers.Remove(timer);
    }

    private void OnDestroy()
    {
        Instance = null;
    }
}
